{% extends "layout.html" %}

{% import "layout.html" as layout with context %}


{% block otherlinks %}
  {% for fmt_name, fmt in formats.items() %}
    {% if format != fmt_name %}
      {% if fmt_name == default_format %}
        {{ layout.head_icon(from_base(format_base), "View as " ~ fmt.label, fmt.icon) }}
      {% else %}
        {{ layout.head_icon(from_base(format_prefix, fmt_name, format_base), "View as " ~ fmt.label, fmt.icon) }}
      {% endif %}
    {% endif %}
  {% endfor %}

  {% if "kernelspec" in nb.metadata %}
    {{ layout.head_icon("#", nb.metadata.kernelspec.display_name + " Kernel", "server") }}
  {% endif %}

  {% if provider_url %}
    {{ layout.head_icon(provider_url, "View on " + provider_label, provider_icon) }}
  {% endif %}

  {{ layout.head_icon(download_url, "Download Notebook", "download", True) }}
{% endblock %}


{% block extra_head %}
  {{ super() }}

  {# Twitter Card #}

  {# Required fields #}
  <meta name="twitter:card" content="summary">
  <meta name="twitter:title" content="{{ notebook_title | default('Notebook on nbviewer') }}">
  <meta name="twitter:description" content="{{ description | default('Check out this Jupyter notebook!') }}">

  {# Optional fields #}
  <meta name="twitter:domain" content="nbviewer.jupyter.org">
  <meta name="twitter:image:src" content="{{ thumbnail | default('http://ipython.org/ipython-doc/dev/_images/ipynb_icon_128x128.png') }}">

  {% block style_base %}
    <link href="{{ static_url("build/notebook.css") }}" rel="stylesheet">
  {% endblock %}

  {% if css_theme %}
    <link href="{{ static_url("css/theme/{{css_theme}}.css") }} rel="stylesheet">
  {% endif %}

  {% block mathjax %}
    <script src="{{ mathjax_url }}MathJax.js?config=TeX-AMS_HTML" type="text/javascript">
    </script>
    <script type="text/javascript">
      init_mathjax = function() {
        if (window.MathJax) {
          // MathJax loaded
          MathJax.Hub.Config({
            TeX: {
              equationNumbers: {
                autoNumber: "AMS",
                useLabelIds: true
              }
            },
            tex2jax: {
              inlineMath: [ ['$','$'], ["\\(","\\)"] ],
              displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
              processEscapes: true,
              processEnvironments: true
            },
            displayAlign: 'center',
            "HTML-CSS": {
              styles: {'.MathJax_Display': {"margin": 0}},
              linebreaks: { automatic: true }
            }
          });
          MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
        }
      }
      init_mathjax();
    </script>
  {% endblock mathjax %}

  {% block ipywidgets %}
    <script>
      (function() {
        function addWidgetsRenderer() {
          var mimeElement = document.querySelector('script[type="application/vnd.jupyter.widget-view+json"]');
          var scriptElement = document.createElement('script');
          var widgetRendererSrc = '{{ ipywidgets_base_url }}@jupyter-widgets/html-manager@*/dist/embed-amd.js';
          var widgetState;

          try {
            widgetState = mimeElement && JSON.parse(mimeElement.innerHTML);

            if (widgetState && (widgetState.version_major < 2 || !widgetState.version_major)) {
              widgetRendererSrc = '{{ ipywidgets_base_url }}jupyter-js-widgets@*/dist/embed.js';
            }
          } catch(e) {}

          scriptElement.src = widgetRendererSrc;
          document.body.appendChild(scriptElement);
        }

        document.addEventListener('DOMContentLoaded', addWidgetsRenderer);
      }());
    </script>
  {% endblock ipywidgets %}
{% endblock extra_head %}


{% block body %}
  {{ link_breadcrumbs(breadcrumbs) }}
  <div id="notebook">
    <div id="notebook-container">
      {{ body | safe}}
    </div>
  </div>
{% endblock %}


{% block extra_script %}
  {{super()}}
  <script>
    $(function(){ $("#menubar").headroom({
      tolerance: 5,
      offset: 205,
      classes: {
        initial: "animated",
        pinned: "slideInDown",
        unpinned: "slideOutUp"
      }
    })});
  </script>
{% endblock extra_script %}


{% block version_info %}
  {{super()}}
  {% if jupyter_info %}
  <p>
    nbconvert version: <a href="https://github.com/jupyter/nbconvert/releases/tag/{{jupyter_info['nbconvert_version']}}">
      {{jupyter_info['nbconvert_version']}}
    </a>
  </p>
  {% endif %}
{% endblock version_info %}


{% block extra_footer %}
  {{super()}}
  {% if date %}
  <p>
    Rendered
    <span class='date' data-date='{{date}}' title='{{date}}'>({{date}})</span>
  </p>
  {% endif %}
{% endblock extra_footer %}
